<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@page isELIgnored="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>机构群组明细</title>
</head>
<e:View id="view">
    <script type="text/javascript" src="<c:url value='/scripts/indexglobal.js'/>"></script>
	<script type="text/javascript" src="<c:url value='/scripts/skin.js'/>"></script>
    <script type="text/javascript">SkinUtil.getSkin();</script>
    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
    
	<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;" >
	
	<e:Dataset id="Dataset_OrgTeamMx" datasetDefinition="DatasetDefinition.dsd" datasetRef="Dataset_OrgTeamMx" pageSize="15" loadDataCommand="Command_Load">
		<e:Field name="id" dataType="string" label="id" maxLength="32" visible="false" />
		<e:Field name="orgTeamId" dataType="string" label="群组ID" maxLength="32" readOnly="true" defaultValue="${param.orgTeamId}" visible="false"/>
		<e:Field name="orgId" dataType="string" label="机构ID" maxLength="32" readOnly="true"/>
		<e:Field name="orgName" dataType="string" label="机构名称" maxLength="200" required="true" dropDown="LookupDropDown_OrgSingle"/>
	</e:Dataset>
	
	<e:Command id="Command_Search" method="queryTeamMx" submitForm="true" action="com.longtop.framework.sys.team.web.OrgTeamAction" showHintInfoOnSuccess="false">
		<e:DatasetInfo name="info1" dataset="Dataset_OrgTeamMx" alwayRefreshClient="true" submitType="none"></e:DatasetInfo>
		<e:Parameter name="orgTeamId" value="${param.orgTeamId}"></e:Parameter>
	</e:Command>
	<e:Command id="Command_Load" method="loadTeamMx" submitForm="true" action="com.longtop.framework.sys.team.web.OrgTeamAction" showHintInfoOnSuccess="false">
		<e:Parameter name="orgTeamId" value="${param.orgTeamId}"></e:Parameter>
	</e:Command>
	
	<e:Command id="Command_Save" action="com.longtop.framework.sys.team.web.OrgTeamAction" method="saveTeamMx" onExecuteSuccess="Command_Save_onExecuteSuccess(command)">
		<e:DatasetInfo name="info1" dataset="Dataset_OrgTeamMx" ></e:DatasetInfo>
	</e:Command>
	
	<e:LookupDropDown id="LookupDropDown_Org" path=""	 windowWidth="600" windowHeight="400" 
			autoDropDown="true" fixed="true" onSelect="LookupDropDown_Org_onSelect(dropdown,iframe,text)" windowCaption="选择部门" alwaysRefresh="true">
	</e:LookupDropDown>
	
	<e:LookupDropDown id="LookupDropDown_OrgSingle" path="/jsp/framework/sys/org/orgDropdown.jsp"	 windowWidth="600" windowHeight="400" 
			autoDropDown="true" fixed="true" onSelect="LookupDropDown_OrgSingle_onSelect(dropdown,iframe,text)" windowCaption="选择部门" alwaysRefresh="true">
	</e:LookupDropDown>			
</div>
	
<body>
	<e:Page id="ePage" action="com.longtop.framework.sys.team.web.OrgTeamAction" style="min-height: 80px; width: 100%; height: 100%;" onAfterLoadPage="ePage_onAfterLoadPage()">
		<table style="width: 100%; height: 100%;" border="0" cellpadding="2" cellspacing="2" width="100%">
			<tr>
				<td width="100%" height="90%" align="left" valign="top">
					<e:Panel id="Panel_team" style="width: 100%; height: 100%" caption="用户群组明细" captionIcon="/images/list_win.gif"
						captionStyle="color:#888888" allowFold="false" showArrowButton="false">
							<table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="2" width="100%" align="center">
								<tr>
									<td>
										<table style="text-align: left;" border="0" cellpadding="0" width="100%" cellspacing="0">
											<tr>
												<td  height="27px" width="1%" nowrap="nowrap">
													<e:RecordNavigator id="RecordNavigator_Role" dataset="Dataset_OrgTeamMx" style="width: 0px" showNavigatorButton="false">
														<e:RecordButton id="RecordButton_insert" label="新增机构" onClick="RecordButton_insert_Onclick()" icon="/images/add.gif"></e:RecordButton>
														<e:RecordButton id="RecordButton_delete" label="删除" onClick="RecordButton_delete_onClick()" icon="/images/delete.gif"></e:RecordButton>
														<e:RecordButton id="RecordButton_submit" label="提交保存" onClick="RecordButton_submit_onClick()" icon="/images/save.gif"></e:RecordButton>
													</e:RecordNavigator>
													<!--  -->
													<e:Text id="Text_orgIdListStr" visible="false" style="width:0px"></e:Text>
												</td>
												<td align="left" nowrap="nowrap">
													<font color="blue">
														<e:CheckBox id="CheckBox_isCheckedRelaNode" label="是否勾选下级机构"  checked="true" checkedValue="true" uncheckedValue="false"></e:CheckBox>
													</font>													
												</td>												
												<td  align="left" width="99%"><e:PageNavigator id="PageNavigator" dataset="Dataset_OrgTeamMx" style="min-width: 200px; height: 25px;;"></e:PageNavigator></td>
											<tr>
										</table>
									</td>	
								</tr>
								<tr>
									<td>
										<e:Grid id="Grid_Result" style="width: 100%; height: 375px;"	dataset="Dataset_OrgTeamMx" showFilterRow="false" showIndicator="true" showIndex="true">
										</e:Grid>
									</td>
								</tr>
							</table>
					</e:Panel>
				</td>
			</tr>
		</table>
	</e:Page>
</body>

<script type="text/javascript">

	//init
	function ePage_onAfterLoadPage(){
		$J("Panel_team").setCaption("机构群组："+Util.decode("${param.teamName}")+ " — 机构详细");
	}
	
	//选择机构：
	function RecordButton_insert_Onclick(){	
		var isCheckedRelaNode = $J("CheckBox_isCheckedRelaNode").getValue();
		var path = "/jsp/framework/sys/org/orgDropdown.jsp";
		path = path+"?showSelect=true&checkedRelaNode="+isCheckedRelaNode;
		LookupDropDown_Org.path = path;
		LookupDropDown_Org.open();
	}
	function LookupDropDown_Org_onSelect(dropdown,iframe,text){
		var dataset = $J(iframe.Dataset_Org);
		var record;
		var selectedNodes =  $J(iframe.DataTree_Org).getSelectedNodes();//选中的节点
		Dataset_OrgTeamMx.disableControls();	
		try {	
			var orgIdListStr=$J("Text_orgIdListStr").getValue();
			for(var i=0; i<selectedNodes.length; i++) {
			   record = selectedNodes[i].record;
			   if (record) {
					var orgId ="'"+record.getValue("orgId")+"',";
					var isExist = (orgIdListStr.indexOf(orgId)!=-1);	//判断记录是否已经存在
					if(isExist){
						continue;
					}
		 			var newRecord = Dataset_OrgTeamMx.insertRecord(false);
					newRecord.setValue("orgId",record.getValue("orgId"));
					newRecord.setValue("orgName",record.getValue("orgName"));
				
					orgIdListStr = orgIdListStr+orgId;					       
			   }
			}						
		}finally {
			Dataset_OrgTeamMx.enableControls();
			Dataset_OrgTeamMx.refreshControls();
		}				
	    $J("Text_orgIdListStr").setValue(orgIdListStr);//组装orgIdListStr			
	}
	
	//删除机构：
	function RecordButton_delete_onClick(){
		var record = Dataset_OrgTeamMx.currentRecord;	
		//若记录为新增的状态！则删除的时候需要同时修改Text_orgIdListStr！
		if(record.state == Constant.RECORD.STATE_INSERT || record.state == Constant.RECORD.STATE_NEW){
			var orgId ="'"+record.getValue("orgId")+"',";	
			var orgIdListStr=$J("Text_orgIdListStr").getValue();
			$J("Text_orgIdListStr").setValue(orgIdListStr.replace(orgId,""));		
		}
		Dataset_OrgTeamMx.deleteRecord(record);
	}	
	
	//修改机构
	function LookupDropDown_OrgSingle_onSelect(dropdown,iframe,text){
		var dataset = $J(iframe.Dataset_Org);
		var node = $J(iframe.DataTree_Org).getCurrentNode();
	    var record = dataset.getCurrentRecord();
	    if(typeof record != "undefined" && record != null){
	    	Dataset_OrgTeamMx.setValue("orgId",record.getValue("orgId"));
	    	Dataset_OrgTeamMx.setValue("orgName",record.getValue("orgName"));
		}
	}
		
	//保存
	function RecordButton_submit_onClick(){
		var flag = Command_Save.execute();
		
		reloadWin = function(){
			window.location.reload();
		}
	
		if(flag){
			var msg=Command_Save.getResponseMessage();
			MsgBox.showInfoMsg(msg,"",[reloadWin]);
		}
	}
	
	//返回
	function Button_Back_onClick(){
		var tabName = "<%=request.getParameter("openerTabName") %>";
		returnToParentTab(tabName,true);
	}	

	//选择(处理dataset的值) 
	function LookupDropDown_User_onSelect(dropdown,iframe,text){
		
		var userDataset = $J(iframe.Dataset_User);
	   	if(userDataset){
	    	var record = userDataset.getCurrentRecord();
	    	if(typeof record != "undefined" && record != null){
	       		Dataset_OrgTeamMx.setValue("userId",record.getValue("userId"));
	   			Dataset_OrgTeamMx.setValue("userName",record.getValue("userName"));
	   			Dataset_OrgTeamMx.setValue("orgName",record.getValue("orgName"));
	    	}
		}		
	}

</script>
</e:View>
</html>